package ch.fusun.baron.player;

import java.util.LinkedList;
import java.util.List;

/**
 * Representation of a player/person
 */
public class Player {

	private int ID;
	private String name;
	private Player father;
	private Player mother;
	private int age = 0;
	private final List<Player> children = new LinkedList<Player>();
	private Gender gender;
	private boolean dead = false;

	/**
	 * Kryo constructor
	 */
	public Player() {
	}

	/**
	 * @param ID
	 *            unique ID of the player
	 * @param name
	 *            The name of the person
	 * @param gender
	 *            The sex of the person
	 */
	public Player(int ID, String name, Gender gender) {
		this.ID = ID;
		this.name = name;
		this.gender = gender;
	}

	/**
	 * @return The name of the player
	 */
	public String getName() {
		return name;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Player) {
			Player oPlayer = (Player) obj;
			return this.ID == oPlayer.ID;
		}
		return false;
	}

	@Override
	public int hashCode() {
		return ID;
	}

	@Override
	public String toString() {
		return name + " (" + age + (isDead() ? ", dead" : "") + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
	}

	/**
	 * @return The father of the player
	 */
	public Player getFather() {
		return father;
	}

	/**
	 * @param father
	 *            The father of the player
	 */
	public void setFather(Player father) {
		this.father = father;
	}

	/**
	 * @return The mother of the player
	 */
	public Player getMother() {
		return mother;
	}

	/**
	 * @param mother
	 *            The mother of the player
	 */
	public void setMother(Player mother) {
		this.mother = mother;
	}

	/**
	 * @return The children
	 */
	public List<Player> getChildren() {
		return children;
	}

	/**
	 * @return The sex of the person
	 */
	public Gender getGender() {
		return gender;
	}

	/**
	 * @param newAge
	 *            The new age
	 */
	public void setAge(int newAge) {
		this.age = newAge;
	}

	/**
	 * @return the age
	 */
	public int getAge() {
		return this.age;
	}

	/**
	 * @return is the player dead?
	 */
	public boolean isDead() {
		return dead;
	}

	/**
	 * @param dead
	 *            Is the player dead?
	 */
	public void setDead(boolean dead) {
		this.dead = dead;
	}

	/**
	 * Kills the {@link Player}
	 */
	public void kill() {
		this.setDead(true);
	}

	/**
	 * @return if haz children
	 */
	public boolean hasChildren() {
		return !this.children.isEmpty();
	}

}
